package excelParseCallback;

import java.math.BigDecimal;
import java.util.Date;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import com.hunk.excel.PoiCallback;
import com.hunk.utils.CommonUtils;
import com.hunk.utils.DateUtils;

/**
 * @author Dengyx
 *
 */
public class ZheLin implements PoiCallback<User> {
	private String area_code;
	private String createuserid;
	private String path;

	public ZheLin(String area_code, String createuserid, String path) {
		super();
		this.area_code = area_code;
		this.createuserid = createuserid;
		this.path = path;
	}

	@Override
	public User parse(HSSFRow hssfRow, HSSFWorkbook hssfWorkBook, HSSFSheet hssfSheet) {
		User u = new User(area_code, createuserid);
		
		u.id = CommonUtils.generateUUID();
		
		HSSFCell name = hssfRow.getCell(1);
		u.name = name.getStringCellValue();
        if ("".equals(u.name)) {
        	return null;
        }
		
        HSSFCell tel = hssfRow.getCell(4);
        String telStr = "";
        if (HSSFCell.CELL_TYPE_NUMERIC == tel.getCellType()) {
        	telStr  = String.valueOf(
    				new BigDecimal(tel.getNumericCellValue()).longValue()
    				);
        } else if (HSSFCell.CELL_TYPE_STRING == tel.getCellType()) {
        	telStr = String.valueOf (
    				Double.parseDouble(tel.getStringCellValue())
    				);
        }
        if (telStr.trim().length() < 11) {
        	u.settle_tel = telStr.trim();
        } else {
        	u.tel = telStr.trim();
        }
        
        HSSFCell major = hssfRow.getCell(3);
        u.major = major.getStringCellValue();
        
        HSSFCell position = hssfRow.getCell(2);
        u.position = position.getStringCellValue();
        
        HSSFCell company = hssfRow.getCell(0);
        u.company = company.getStringCellValue();
        
        HSSFCell bakup = hssfRow.getCell(5);
        if (HSSFCell.CELL_TYPE_NUMERIC == bakup.getCellType()) {
        	u.bakup = String.valueOf(
        				new BigDecimal(bakup.getNumericCellValue()).longValue()
        				);
        } else if (HSSFCell.CELL_TYPE_STRING == bakup.getCellType()) {
        	u.bakup = String.valueOf (
        				Double.parseDouble(bakup.getStringCellValue())
        				);
        }
        
        u.savetime = DateUtils.parseDateToString(new Date(), DateUtils.yyyy_MM_dd);
        
		return u;
	}

	@Override
	public String getPath() {
		return path;
	}
	@Override
	public void check(HSSFWorkbook hssfWorkbook) {
		// TODO Auto-generated method stub
	}
}
